Proper connect_port
[juce-lv2.git] / juce / source / extras / the jucer / src / model / components / jucer_GroupComponentHandler.h
blobfd820442bc2471a44757f83d1b1f2dbe6efcda47
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCER_GROUPCOMPONENTHANDLER_JUCEHEADER__
27 #define __JUCER_GROUPCOMPONENTHANDLER_JUCEHEADER__
30 //==============================================================================
31 /**
33 class GroupComponentHandler : public ComponentTypeHandler
35 public:
36 //==============================================================================
37 GroupComponentHandler()
38 : ComponentTypeHandler ("Group Box", "GroupComponent", typeid (GroupComponent), 200, 150)
40 registerColour (GroupComponent::outlineColourId, "outline", "outlinecol");
41 registerColour (GroupComponent::textColourId, "text", "textcol");
44 //==============================================================================
45 Component* createNewComponent (JucerDocument*)
47 return new GroupComponent ("new group", "group");
50 XmlElement* createXmlFor (Component* comp, const ComponentLayout* layout)
52 GroupComponent* const g = (GroupComponent*) comp;
54 XmlElement* e = ComponentTypeHandler::createXmlFor (comp, layout);
55 e->setAttribute ("title", g->getText());
57 GroupComponent defaultComp (String::empty, String::empty);
59 if (g->getTextLabelPosition().getFlags() != defaultComp.getTextLabelPosition().getFlags())
60 e->setAttribute ("textpos", g->getTextLabelPosition().getFlags());
62 return e;
65 bool restoreFromXml (const XmlElement& xml, Component* comp, const ComponentLayout* layout)
67 GroupComponent* const g = (GroupComponent*) comp;
69 if (! ComponentTypeHandler::restoreFromXml (xml, comp, layout))
70 return false;
72 g->setText (xml.getStringAttribute ("title", g->getText()));
73 g->setTextLabelPosition (Justification (xml.getIntAttribute ("textpos", g->getTextLabelPosition().getFlags())));
75 return true;
78 const String getCreationParameters (Component* component)
80 GroupComponent* g = dynamic_cast <GroupComponent*> (component);
82 return quotedString (component->getName())
83 + ",\n"
84 + quotedString (g->getText());
87 void fillInCreationCode (GeneratedCode& code, Component* component, const String& memberVariableName)
89 ComponentTypeHandler::fillInCreationCode (code, component, memberVariableName);
91 GroupComponent* const g = dynamic_cast <GroupComponent*> (component);
93 String s;
95 GroupComponent defaultComp (String::empty, String::empty);
97 if (g->getTextLabelPosition().getFlags() != defaultComp.getTextLabelPosition().getFlags())
99 s << memberVariableName << "->setTextLabelPosition ("
100 << justificationToCode (g->getTextLabelPosition())
101 << ");\n";
104 s << getColourIntialisationCode (component, memberVariableName)
105 << '\n';
107 code.constructorCode += s;
110 void getEditableProperties (Component* component, JucerDocument& document, Array <PropertyComponent*>& properties)
112 ComponentTypeHandler::getEditableProperties (component, document, properties);
114 properties.add (new GroupTitleProperty ((GroupComponent*) component, document));
115 properties.add (new GroupJustificationProperty ((GroupComponent*) component, document));
117 addColourProperties (component, document, properties);
120 private:
121 //==============================================================================
122 class GroupTitleProperty : public ComponentTextProperty <GroupComponent>
124 public:
125 GroupTitleProperty (GroupComponent* component_, JucerDocument& document_)
126 : ComponentTextProperty <GroupComponent> ("text", 200, false, component_, document_)
129 //==============================================================================
130 void setText (const String& newText)
132 document.perform (new GroupTitleChangeAction (component, *document.getComponentLayout(), newText),
133 "Change group title");
136 const String getText() const
138 return component->getText();
141 private:
142 class GroupTitleChangeAction : public ComponentUndoableAction <GroupComponent>
144 public:
145 GroupTitleChangeAction (GroupComponent* const comp, ComponentLayout& layout, const String& newName_)
146 : ComponentUndoableAction <GroupComponent> (comp, layout),
147 newName (newName_)
149 oldName = comp->getText();
152 bool perform()
154 showCorrectTab();
155 getComponent()->setText (newName);
156 changed();
157 return true;
160 bool undo()
162 showCorrectTab();
163 getComponent()->setText (oldName);
164 changed();
165 return true;
168 String newName, oldName;
172 //==============================================================================
173 class GroupJustificationProperty : public JustificationProperty,
174 public ChangeListener
176 public:
177 GroupJustificationProperty (GroupComponent* const group_, JucerDocument& document_)
178 : JustificationProperty ("layout", true),
179 group (group_),
180 document (document_)
182 document.addChangeListener (this);
185 ~GroupJustificationProperty()
187 document.removeChangeListener (this);
190 void setJustification (const Justification& newJustification)
192 document.perform (new GroupJustifyChangeAction (group, *document.getComponentLayout(), newJustification),
193 "Change text label position");
196 const Justification getJustification() const
198 return group->getTextLabelPosition();
201 void changeListenerCallback (ChangeBroadcaster*) { refresh(); }
203 private:
204 GroupComponent* const group;
205 JucerDocument& document;
207 class GroupJustifyChangeAction : public ComponentUndoableAction <GroupComponent>
209 public:
210 GroupJustifyChangeAction (GroupComponent* const comp, ComponentLayout& layout, const Justification& newState_)
211 : ComponentUndoableAction <GroupComponent> (comp, layout),
212 newState (newState_),
213 oldState (comp->getTextLabelPosition())
217 bool perform()
219 showCorrectTab();
220 getComponent()->setTextLabelPosition (newState);
221 changed();
222 return true;
225 bool undo()
227 showCorrectTab();
228 getComponent()->setTextLabelPosition (oldState);
229 changed();
230 return true;
233 Justification newState, oldState;
239 #endif // __JUCER_GROUPCOMPONENTHANDLER_JUCEHEADER__